package observer;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class Senzor implements Subject
{
	private List <Observer> obs = new LinkedList <Observer>();
	private int valCurenta=0;
	
   //Adauga un Observer
	public void addObserver(Observer o) 
	{
		obs.add(o);
		
	}

	//Sterge un Observer
	public void removeObserver(Observer o)
	{
		obs.remove(o);
		
	}
	
	//Notifica Observerii
	public void notifyObserver()
	{
		Iterator i = obs.iterator();
		while (i.hasNext())
		{
			Observer o= (Observer) i.next();
			o.upDate(this);
		}
	}
	
	//Genereaza un numar aleator
	public void generare ()
	{
		Random serieRandom= new Random();
		valCurenta = serieRandom.nextInt(80);
		notifyObserver();
	}

	//Returneaza valoarea curenta
	public int getVal()
	{
		   return valCurenta;
	}
}
